package damngoodcoffee.smart.interpreters;

import com.google.inject.Inject;
import com.google.inject.Provider;

import damngoodcoffee.smart.Parser;
import damngoodcoffee.smart.commands.Command;
import damngoodcoffee.smart.commands.ParseCommand;
import damngoodcoffee.smart.tags.EndTag;
import damngoodcoffee.smart.tags.StartTag;

public class AnchorInterpreter implements Interpreter {
    private String file;
    private Provider<Parser> parser;

    @Inject
    public AnchorInterpreter(Provider<Parser> parser) {
	this.parser = parser;
    }

    public void interpret(StartTag t) {
	file = t.getAtts().getValue("href");
    }

    public boolean canInterpret(StartTag t) {
	return t.getLocalName().equals("a")
		&& (t.getAtts().getValue("rel") == null || (t.getAtts()
			.getValue("rel") != null && !t.getAtts()
			.getValue("rel").equals("nofollow")));
    }

    public void interpret(String value) {

    }

    public Command getCommand() {
	return new ParseCommand(parser.get(), file);
    }

    public void interpret(EndTag t) throws InterpreterException {

    }

    public boolean canInterpret(EndTag t) {
	return t.getLocalName().equals("a");
    }
}
